home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libs / readline / keymaps.c < prev    next >
C/C++ Source or Header  |  1995-09-19  |  5KB  |  202 lines

  1. /* keymaps.c -- Functions and keymaps for the GNU Readline library. */
  2.  
  3. /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Readline, a library for reading lines
  6.    of text with interactive input and history editing.
  7.  
  8.    Readline is free software; you can redistribute it and/or modify it
  9.    under the terms of the GNU General Public License as published by the
  10.    Free Software Foundation; either version 1, or (at your option) any
  11.    later version.
  12.  
  13.    Readline is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with Readline; see the file COPYING.  If not, write to the Free
  20.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25.  
  26. #define READLINE_LIBRARY
  27.  
  28. #if defined (HAVE_STDLIB_H)
  29. #  include <stdlib.h>
  30. #else
  31. #  include "ansi_stdlib.h"
  32. #endif /* HAVE_STDLIB_H */
  33.  
  34. #include "rlconf.h"
  35. #include "keymaps.h"
  36. #include "emacs_keymap.c"
  37.  
  38. #if defined (VI_MODE)
  39. #include "vi_keymap.c"
  40. #endif
  41.  
  42. extern int rl_do_lowercase_version ();
  43. extern int rl_rubout (), rl_insert ();
  44.  
  45. #if defined (STATIC_MALLOC)
  46. static char *xmalloc (), *xrealloc ();
  47. #else
  48. extern char *xmalloc (), *xrealloc ();
  49. #endif /* STATIC_MALLOC */
  50.  
  51. /* **************************************************************** */
  52. /*                                    */
  53. /*              Functions for manipulating Keymaps.        */
  54. /*                                    */
  55. /* **************************************************************** */
  56.  
  57.  
  58. /* Return a new, empty keymap.
  59.    Free it with free() when you are done. */
  60. Keymap
  61. rl_make_bare_keymap ()
  62. {
  63.   register int i;
  64.   Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
  65.  
  66.   for (i = 0; i < KEYMAP_SIZE; i++)
  67.     {
  68.       keymap[i].type = ISFUNC;
  69.       keymap[i].function = (Function *)NULL;
  70.     }
  71.  
  72.   for (i = 'A'; i < ('Z' + 1); i++)
  73.     {
  74.       keymap[i].type = ISFUNC;
  75.       keymap[i].function = rl_do_lowercase_version;
  76.     }
  77.  
  78.   return (keymap);
  79. }
  80.  
  81. /* Return a new keymap which is a copy of MAP. */
  82. Keymap
  83. rl_copy_keymap (map)
  84.      Keymap map;
  85. {
  86.   register int i;
  87.   Keymap temp = rl_make_bare_keymap ();
  88.  
  89.   for (i = 0; i < KEYMAP_SIZE; i++)
  90.     {
  91.       temp[i].type = map[i].type;
  92.       temp[i].function = map[i].function;
  93.     }
  94.   return (temp);
  95. }
  96.  
  97. /* Return a new keymap with the printing characters bound to rl_insert,
  98.    the uppercase Meta characters bound to run their lowercase equivalents,
  99.    and the Meta digits bound to produce numeric arguments. */
  100. Keymap
  101. rl_make_keymap ()
  102. {
  103.   register int i;
  104.   Keymap newmap;
  105.  
  106.   newmap = rl_make_bare_keymap ();
  107.  
  108.   /* All ASCII printing characters are self-inserting. */
  109.   for (i = ' '; i < 127; i++)
  110.     newmap[i].function = rl_insert;
  111.  
  112.   newmap[TAB].function = rl_insert;
  113.   newmap[RUBOUT].function = rl_rubout;
  114.   newmap[CTRL('H')].function = rl_rubout;
  115.  
  116. #if KEYMAP_SIZE > 128
  117.   /* Printing characters in some 8-bit character sets. */
  118.   for (i = 128; i < 160; i++)
  119.     newmap[i].function = rl_insert;
  120.  
  121.   /* ISO Latin-1 printing characters should self-insert. */
  122.   for (i = 160; i < 256; i++)
  123.     newmap[i].function = rl_insert;
  124. #endif /* KEYMAP_SIZE > 128 */
  125.  
  126.   return (newmap);
  127. }
  128.  
  129. /* Free the storage associated with MAP. */
  130. void
  131. rl_discard_keymap (map)
  132.      Keymap (map);
  133. {
  134.   int i;
  135.  
  136.   if (!map)
  137.     return;
  138.  
  139.   for (i = 0; i < KEYMAP_SIZE; i++)
  140.     {
  141.       switch (map[i].type)
  142.     {
  143.     case ISFUNC:
  144.       break;
  145.  
  146.     case ISKMAP:
  147.       rl_discard_keymap ((Keymap)map[i].function);
  148.       break;
  149.  
  150.     case ISMACR:
  151.       free ((char *)map[i].function);
  152.       break;
  153.     }
  154.     }
  155. }
  156.  
  157. #if defined (STATIC_MALLOC)
  158.  
  159. /* **************************************************************** */
  160. /*                                    */
  161. /*            xmalloc and xrealloc ()                     */
  162. /*                                    */
  163. /* **************************************************************** */
  164.  
  165. static void memory_error_and_abort ();
  166.  
  167. static char *
  168. xmalloc (bytes)
  169.      int bytes;
  170. {
  171.   char *temp = (char *)malloc (bytes);
  172.  
  173.   if (!temp)
  174.     memory_error_and_abort ();
  175.   return (temp);
  176. }
  177.  
  178. static char *
  179. xrealloc (pointer, bytes)
  180.      char *pointer;
  181.      int bytes;
  182. {
  183.   char *temp;
  184.  
  185.   if (!pointer)
  186.     temp = (char *)malloc (bytes);
  187.   else
  188.     temp = (char *)realloc (pointer, bytes);
  189.  
  190.   if (!temp)
  191.     memory_error_and_abort ();
  192.   return (temp);
  193. }
  194.  
  195. static void
  196. memory_error_and_abort ()
  197. {
  198.   fprintf (stderr, "readline: Out of virtual memory!\n");
  199.   abort ();
  200. }
  201. #endif /* STATIC_MALLOC */
  202.